#ifndef __BUFFERQUEUE_HEADERFILE__
#define __BUFFERQUEUE_HEADERFILE__
/* header files */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <semaphore.h>

/* macro definition */
#define MAXTASK     256
/* type declaration */
enum elemlen{BYTE=1, WORD=2, DOUBLE=4, QWAD=8};

typedef struct buffer_queue{
    void** array;   // 存储元素首地址，而不是存储整个元素
    size_t capacity;   
    size_t elemsize;    // 队列元素所占内存字节数

    size_t head;
    size_t tail;    // always empty
    size_t size;    // 队列中现存几个元素

    sem_t lock;
    sem_t full;     
    sem_t empty;    
    
    ssize_t (*enque)(struct buffer_queue* self, void* elem);    // not thread_safe
    void* (*deque)(struct buffer_queue* self);  // not thread safe
    void* (*peek)(struct buffer_queue* self);   // thread safe 
    size_t (*getsize)(struct buffer_queue* self);   // thread safe
}bufque_t;

/* function declaration */
int bufque_init(bufque_t* que, size_t quesize,size_t elemsize);
int bufque_destroy(bufque_t* que);


#endif
